package com.cloud.shopping.goods.controller;


import com.cloud.shopping.goods.model.Category;
import com.cloud.shopping.goods.service.CategoryService;
import com.cloud.shopping.tool.RespResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品类目 前端控制器
 * </p>
 *
 * @author John.zhang
 * @since 2020-12-28
 */
@Api(tags = "品类模块")
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /****
     * 根据分类父ID查询子分类
     */
    @GetMapping(value = "/parent/{id}")
    public RespResult<List<Category>> findByParentId(@PathVariable("id")Integer id){
        return RespResult.ok(categoryService.findByParentId(id));
    }

    /****
     * 根据分类查询分类信息
     */
    @GetMapping(value = "/{id}")
    public RespResult<Category> one(@PathVariable(value = "id")Integer id){
        Category category = categoryService.getById(id);
        return RespResult.ok(category);
    }

}

